package com.example.mapp.buildSql;

import com.example.entity.SpotCheckPlan;
import com.example.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

/**
 * 监管场所自定义查询导出
 */
public class SpotCheckPlanMappSql {
    /**
     *
     * 查询的SQL
     * findList
     * @param
     * @return
     */
    public String findlists(SpotCheckPlan spotCheckPlan){
        StringBuffer sb = new StringBuffer();
        sb.append(" select ");
        sb.append("  id AS id, ");
        sb.append("  plan_name AS 'planName', ");
        sb.append("  company AS 'company', ");
        sb.append("  plan_start_time AS 'planStartTime', ");
        sb.append("  plan_end_time AS 'planEndTime', ");
        sb.append("  create_by AS 'createBy', ");
        sb.append("  create_date AS 'createDate', ");
        sb.append("  update_by AS 'updateBy', ");
        sb.append("  update_date AS 'updateDate',");
        sb.append("  is_check AS 'isCheck',");
        sb.append("  is_send_message AS 'isSendMessage',");
        sb.append("  party_id AS 'partyId',");
        sb.append("  del_flag AS 'delFlag' ");
        sb.append("  from spot_check_plan  where del_flag='1' ");

        if(spotCheckPlan.getPartyId() !=null){
                sb.append(" and party_id="+spotCheckPlan.getPartyId());
        }

        if(spotCheckPlan.getId() !=null){
            sb.append(" and id="+spotCheckPlan.getId());
        }
        if(StringUtil.isNotBlank(spotCheckPlan.getPlanName())){
            sb.append(" and plan_name = '"+spotCheckPlan.getPlanName()+"'");
        }
        if(StringUtil.isNotBlank(spotCheckPlan.getPlanStartTime())){
            sb.append(" and date_format(plan_start_time, '%Y%m%d')>='"+spotCheckPlan.getPlanStartTime()+"'");
        }
        if (spotCheckPlan.getPlanEndTime() != null) {
            sb.append("and date_format(plan_end_time, '%Y%m%d') <='" + spotCheckPlan.getPlanEndTime() + "'");
        }
        if (StringUtils.isNotEmpty(spotCheckPlan.getStartTime())) {
            sb.append(" and date_format(plan_start_time, '%Y%m%d') ='" + spotCheckPlan.getStartTime() + "'");
        }
        if(StringUtils.isNotEmpty(spotCheckPlan.getIsCheck())){
            sb.append(" and is_check = '"+spotCheckPlan.getIsCheck()+"'");
        }

        sb.append(" order by plan_start_time desc ");



        return sb.toString();
    }






}
